package com.xiang.bean;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

//@Component

@Aspect
public class MyTestAop {

	@Pointcut("execution(* *.myTest(..))")
	public void pointCut(){
	}

	@Before("pointCut()")
	public void before(JoinPoint joinPoint){
		Object[] args = joinPoint.getArgs(); //获取方法参数
		String name = joinPoint.getSignature().getName(); //获取方法名
		Object target = joinPoint.getTarget();//获取目标对象
		System.out.println("这是前置通知Before");
	}

	@After("pointCut()")
	public void after(){
		System.out.println("这是最终通知 After");
	}

	@AfterReturning(value = "pointCut()",returning = "result")
	public void afterReturning(Object result){
		//System.out.println("返回结果集。。。。"+result);
		System.out.println("这是一个返回通知 AfterReturning");
	}



	@Around("pointCut()")
	public Object aroud(ProceedingJoinPoint joinPoint){
		Object proceed = null;
		try {
			//前置通知
			System.out.println("现在是aroud的前置通知。。。"+joinPoint.getSignature().getName());
			//执行目标方法
			proceed = joinPoint.proceed();
			System.out.println("aroud返回通知");
		} catch (Throwable throwable) {
			System.out.println("aroud异常通知");
			throw new RuntimeException();
		}finally {
			System.out.println("aroud后置通知");
		}
		return proceed;
	}

}
